package com.ruoyi.project.module.vip.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.vip.domain.Vip;
import com.ruoyi.project.module.vip.service.IVipService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * vip 信息操作处理
 * 
 * @author frey
 * @date 2018-11-13
 */
@Controller
@RequestMapping("/module/vip")
public class VipController extends BaseController
{
    private String prefix = "module/vip";
	
	@Autowired
	private IVipService vipService;
	
	@RequiresPermissions("module:vip:view")
	@GetMapping()
	public String vip()
	{
	    return prefix + "/vip";
	}
	
	/**
	 * 查询vip列表
	 */
	@RequiresPermissions("module:vip:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Vip vip)
	{
		startPage();
        List<Vip> list = vipService.selectVipList(vip);
		return getDataTable(list);
	}
	
	/**
	 * 新增vip
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存vip
	 */
	@RequiresPermissions("module:vip:add")
	@Log(title = "vip", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Vip vip)
	{		
		return toAjax(vipService.insertVip(vip));
	}

	/**
	 * 修改vip
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Vip vip = vipService.selectVipById(id);
		mmap.put("vip", vip);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存vip
	 */
	@RequiresPermissions("module:vip:edit")
	@Log(title = "vip", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Vip vip)
	{		
		return toAjax(vipService.updateVip(vip));
	}
	
	/**
	 * 删除vip
	 */
	@RequiresPermissions("module:vip:remove")
	@Log(title = "vip", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(vipService.deleteVipByIds(ids));
	}
	
}
